package com.etc.entity;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class EquipmentFactory {

	public static Equipment createEquipment(String classType ,String equipId, String equipName, int attrHeal, int attrImage, int attrAttack, 
			int attrCrit, int attrDefense, int attrSpeed, String type) {
		//设置参数
		Class[] paramTypes =new Class[] {String.class, String.class, int.class, int.class, 
				int.class, int.class, int.class, int.class, String.class };
		Object[] params = new Object[] {equipId, equipName, attrHeal, attrImage, attrAttack, 
				attrCrit, attrDefense, attrSpeed, type};
		Equipment equipment = null;
		Class clazz = null;
		
		String className = "com.etc.entity." + classType;
		Constructor<Equipment> constructor;
		try {
			clazz = Class.forName(className);
			constructor = clazz.getConstructor(paramTypes);
			equipment = constructor.newInstance(params);
		} catch (NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return equipment;
		
	}
}
